package com.aurora.source.authority.presenter;

import android.content.Context;
import android.util.Log;

import com.aurora.source.authority.bean.PersonAuthBean;
import com.aurora.source.authority.view.IAuthManageView;
import com.aurora.source.base.BaseBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.constant.AuroraConstants;
import com.aurora.source.util.netutil.SubscriberObserver;

import java.util.HashMap;
import java.util.Map;

public class AuthManagePresenter extends BasePresenter<IAuthManageView> {

    public AuthManagePresenter(IAuthManageView baseView) {
        super(baseView);
    }

    public void AuthManage(Context context, Map<String, String> params) {
        requestMethod.authManage(params, new SubscriberObserver<BaseBean<PersonAuthBean>>(context,"正在加载中...") {
            @Override
            public void onSuccess(BaseBean<PersonAuthBean> personAuthBeanBaseBean) {
                Log.e("sss",personAuthBeanBaseBean.getMsg());
                if (personAuthBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)) {
                    baseView.onAuthManageSuccess(personAuthBeanBaseBean.getData());
                } else {
                    baseView.onAuthManageFail(personAuthBeanBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onAuthManageFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    public void regist(Context context, String userAccount, String userStatus){
        Map<String,String> params = new HashMap<>();
        params.put("userAccount",userAccount);
        params.put("userStatus",userStatus+"");
        requestMethod.regist(params, new SubscriberObserver<BaseBean>(context,"正在注销中，请稍候...") {
            @Override
            public void onSuccess(BaseBean baseBean) {
                if(baseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onRegistSuccess(baseBean.getMsg());
                }else {
                    baseView.onRegistFail(baseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onRegistFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    public void updateUserRole(String userId, String processIds, String sysRoleCode) {
        Map<String,String> params = new HashMap<>();
        params.put("userId",userId);
        params.put("processIds",processIds+"");
        params.put("sysRoleCodes",sysRoleCode+"");
        requestMethod.updateUserRole(params, new SubscriberObserver<BaseBean>((Context) baseView,"正在修改授权信息，请稍候...") {
            @Override
            public void onSuccess(BaseBean baseBean) {
                if(baseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onUpdataSuccess(baseBean.getMsg());
                }else {
                    baseView.onUpdataFail(baseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onUpdataFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }
}
